
            var receiveReq = getXmlHttpRequestObject();
            var sendReq = getXmlHttpRequestObject();
            var mTimer;

            function receive() {
                if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
                    receiveReq.open("GET", from_url, true);
                    receiveReq.onreadystatechange = handleReceiveReq;
                    receiveReq.send(null);
                }
            }
            
            function handleReceiveReq() {
                if (receiveReq.readyState == 4) {
                    var messages = document.getElementById('messages');
                    var response = receiveReq.responseText;
                    messages.innerHTML = messages.innerHTML + "<br/>" + response;
                }
                // whatever response we get back, wait 2 secs, start receive() again
                mTimer = setTimeout('receive();',2000);
            }
            
            function send() {
                if (sendReq.readyState == 4 || sendReq.readyState == 0) {
                    sendReq.open("POST", to_url, true);
                    sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                    sendReq.onreadystatechange = handleSendReq; 
                    var param = 'uid=1';
                    param += '&fid=1';
                    param += '&msg=' + document.getElementById('mymsg').value;
                    sendReq.send(param);
                    document.getElementById('mymsg').value = '';
                }							
            }
            //When our message has been sent, update our page.
            function handleSendReq() {
                //Clear out the existing timer so we don't have
                //multiple timer instances running.
                clearInterval(mTimer);
                //receive();
            }

            //Gets the browser specific XmlHttpRequest Object
            function getXmlHttpRequestObject() {
                if (window.XMLHttpRequest) {
                    return new XMLHttpRequest();
                } else if(window.ActiveXObject) {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                } else {
                    document.getElementById('messages').innerHTML =
                        'Status: Cound not create XmlHttpRequest Object.' +
                        'Consider upgrading your browser.';
                }
            }